package com.xxg.renrenproduct.controller;

import com.xxg.renrencommon.domain.result.BaseResult;
import com.xxg.renrenproduct.domain.query.AddProductCollectionQuery;
import com.xxg.renrenproduct.domain.query.GatherProductQuery;
import com.xxg.renrenproduct.service.ProductGatherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 商品采集管理
 *
 * @author szj
 * @date 2021/11/29
 */
@Api(tags = "商品采集管理")
@RestController
@RequestMapping("/productGather")
@AllArgsConstructor
public class ProductGatherController {
    private final ProductGatherService productGatherService;

    @ApiOperation("采集商品")
    @RequestMapping(value = "gather", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE,
            consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({@ApiImplicitParam(name = "query", value = "采集商品参数", required = true, dataType = "GatherProductQuery")})
    public BaseResult<Void> add(@RequestBody @Validated GatherProductQuery query, HttpServletRequest request) {
        String userId = request.getHeader("userId");
        return productGatherService.gather(userId, query);
    }

    // 一键采集
}
